package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SafeInformation;
import com.ruoyi.system.service.ISafeInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 实验守则Controller
 * 
 * @author kk
 * @date 2023-06-20
 */
@RestController
@RequestMapping("/system/information")
public class SafeInformationController extends BaseController
{
    @Autowired
    private ISafeInformationService safeInformationService;

    /**
     * 查询实验守则列表
     */
    @PreAuthorize("@ss.hasPermi('system:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(SafeInformation safeInformation)
    {
        startPage();
        List<SafeInformation> list = safeInformationService.selectSafeInformationList(safeInformation);
        return getDataTable(list);
    }

    /**
     * 导出实验守则列表
     */
    @PreAuthorize("@ss.hasPermi('system:information:export')")
    @Log(title = "实验守则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafeInformation safeInformation)
    {
        List<SafeInformation> list = safeInformationService.selectSafeInformationList(safeInformation);
        ExcelUtil<SafeInformation> util = new ExcelUtil<SafeInformation>(SafeInformation.class);
        util.exportExcel(response, list, "实验守则数据");
    }

    /**
     * 获取实验守则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:information:query')")
    @GetMapping(value = "/{safeID}")
    public AjaxResult getInfo(@PathVariable("safeID") String safeID)
    {
        return success(safeInformationService.selectSafeInformationBySafeID(safeID));
    }

    /**
     * 新增实验守则
     */
    @PreAuthorize("@ss.hasPermi('system:information:add')")
    @Log(title = "实验守则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafeInformation safeInformation)
    {
        return toAjax(safeInformationService.insertSafeInformation(safeInformation));
    }

    /**
     * 修改实验守则
     */
    @PreAuthorize("@ss.hasPermi('system:information:edit')")
    @Log(title = "实验守则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafeInformation safeInformation)
    {
        return toAjax(safeInformationService.updateSafeInformation(safeInformation));
    }

    /**
     * 删除实验守则
     */
    @PreAuthorize("@ss.hasPermi('system:information:remove')")
    @Log(title = "实验守则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{safeIDs}")
    public AjaxResult remove(@PathVariable String[] safeIDs)
    {
        return toAjax(safeInformationService.deleteSafeInformationBySafeIDs(safeIDs));
    }
}
